<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box{
            color: pink;
        }
    </style>
</head>

<body>
    <div id="div1">div1</div>
    <div id="div2">
        div2
        <p id="p1" class="box">p1</p>
    </div>
    <div id="div3"></div>
    <span id="span1">span1</span>
    <ul>
        <li>111</li>
        <li>222</li>
        <li>333</li>
    </ul>
    <script>
        let div1=document.querySelector("#div1")
        console.log(div1)
        let p1=document.querySelector(".box")
        console.log(p1)
        let divs=document.getElementsByTagName("div")
        console.log(divs)
        divs[0].append("添加内容")
        //创建元素
        let h1=document.createElement("h1")
        h1.innerHTML="这是h1标签"
        divs[2].append(h1)
        h3 = document.createElement("h3")
        h3.innerText = "h3"
        divs[1].insertBefore(h3, p1)
        //删除
        span1=document.getElementById("span1")
        //span1.remove()
        let list=document.getElementsByTagName("ul")
        console.log(list)
        console.log(list[0].firstElementChild)
        console.log(list[0].firstChild)//换行符元素节点
        console.log(list[0].firstElementChild.nextElementSibling)
        //另一种删除方法
        // list[0].children[1].remove()
        //list[0].removeChild(list[0].children[1])

        console.log(p1.parentElement)
        // p1.parentElement.removeChild(p1)
        // divs[1].removeChild(p1)
</script>
</body>

</html>